package com.sg.business.commons.editingsupport;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.swt.widgets.Composite;

import com.sg.business.model.WFHumanTaskSetting;

public class SpinnerEditingSupport extends EditingSupport {

	private ColumnViewer viewer;

	public SpinnerEditingSupport(ColumnViewer viewer) {
		super(viewer);
		this.viewer = viewer;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		if (element instanceof WFHumanTaskSetting) {
			return new SpinnerCellEditor((Composite) viewer.getControl());
		}
		return null;
	}

	@Override
	protected boolean canEdit(Object element) {
		if (element instanceof WFHumanTaskSetting) {
			return true;
		}
		return false;
	}

	@Override
	protected Object getValue(Object element) {
		if (element instanceof WFHumanTaskSetting) {
			WFHumanTaskSetting wfHumanTaskSetting = (WFHumanTaskSetting) element;
			Object value = wfHumanTaskSetting
					.getValue(WFHumanTaskSetting.F_DELAY_SETTING);
			return value;
		}
		return null;
	}

	@Override
	protected void setValue(Object element, Object value) {
		if (element instanceof WFHumanTaskSetting) {
			WFHumanTaskSetting wfHumanTaskSetting = (WFHumanTaskSetting) element;
			wfHumanTaskSetting.setValue(WFHumanTaskSetting.F_DELAY_SETTING,
					value);
			viewer.refresh(element);
		}
	}

}
